﻿using System.Windows;
using System.Windows.Input;
using JDKD.BMCS.Business;
using NutShell.DesignPattern;

namespace JDKD.BMCS.AppUI
{
        /// <summary>
        /// LoginWindow.xaml 的交互逻辑
        /// </summary>
        public partial class ShiftWindow : Window
        {
                

                public ShiftWindow()
                {
                        InitializeComponent();
                }

                #region 字段

                private BusinessCache cache = Singleton<BusinessCache>.Instance;

                #endregion 字段

                private void Window_Loaded(object sender, RoutedEventArgs e)
                {
                        
                        Channel1LeftRadioButton.IsChecked = cache.Channels[1].ShiftType == ShiftType.自动;
                        Channel1RightRadioButton.IsChecked = cache.Channels[1].ShiftType == ShiftType.手动;

                        Channel2LeftRadioButton.IsChecked = cache.Channels[2].ShiftType == ShiftType.自动;
                        Channel2RightRadioButton.IsChecked = cache.Channels[2].ShiftType == ShiftType.手动;

                        Channel3LeftRadioButton.IsChecked = cache.Channels[3].ShiftType == ShiftType.自动;
                        Channel3RightRadioButton.IsChecked = cache.Channels[3].ShiftType == ShiftType.手动;

                        Channel4LeftRadioButton.IsChecked = cache.Channels[4].ShiftType == ShiftType.自动;
                        Channel4RightRadioButton.IsChecked = cache.Channels[4].ShiftType == ShiftType.手动;

                        Channel5LeftRadioButton.IsChecked = cache.Channels[5].ShiftType == ShiftType.自动;
                        Channel5RightRadioButton.IsChecked = cache.Channels[5].ShiftType == ShiftType.手动;

                        Channel6LeftRadioButton.IsChecked = cache.Channels[6].ShiftType == ShiftType.自动;
                        Channel6RightRadioButton.IsChecked = cache.Channels[6].ShiftType == ShiftType.手动;

                        Channel7LeftRadioButton.IsChecked = cache.Channels[7].ShiftType == ShiftType.自动;
                        Channel7RightRadioButton.IsChecked = cache.Channels[7].ShiftType == ShiftType.手动;

                        Channel8LeftRadioButton.IsChecked = cache.Channels[8].ShiftType == ShiftType.自动;
                        Channel8RightRadioButton.IsChecked = cache.Channels[8].ShiftType == ShiftType.手动;

                        
                }

                private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
                {
                        if (e.ChangedButton == MouseButton.Left)
                        {
                                this.DragMove();
                        }
                }

                private void AcceptButton_Click(object sender, RoutedEventArgs e)
                {
                        cache.Channels[1].ShiftType = Channel1LeftRadioButton.IsChecked.GetValueOrDefault() ? ShiftType.自动 : ShiftType.手动;
                        cache.Channels[2].ShiftType = Channel2LeftRadioButton.IsChecked.GetValueOrDefault() ? ShiftType.自动 : ShiftType.手动;
                        cache.Channels[3].ShiftType = Channel3LeftRadioButton.IsChecked.GetValueOrDefault() ? ShiftType.自动 : ShiftType.手动;
                        cache.Channels[4].ShiftType = Channel4LeftRadioButton.IsChecked.GetValueOrDefault() ? ShiftType.自动 : ShiftType.手动;

                        cache.Channels[5].ShiftType = Channel5LeftRadioButton.IsChecked.GetValueOrDefault() ? ShiftType.自动 : ShiftType.手动;
                        cache.Channels[6].ShiftType = Channel6LeftRadioButton.IsChecked.GetValueOrDefault() ? ShiftType.自动 : ShiftType.手动;
                        cache.Channels[7].ShiftType = Channel7LeftRadioButton.IsChecked.GetValueOrDefault() ? ShiftType.自动 : ShiftType.手动;
                        cache.Channels[8].ShiftType = Channel8LeftRadioButton.IsChecked.GetValueOrDefault() ? ShiftType.自动 : ShiftType.手动;

                        Close();
                }

                private void CancelButton_Click(object sender, RoutedEventArgs e)
                {
                        Close();
                }
        }
}